#include "LightHandler.h"


LightHandler::~LightHandler()
{
}



void LightHandler:: Init()
{
     //inizilaizzazione valori di default
    GLfloat materiale_ambiente[4] = {0.05,0.5,0.05,1};
    GLfloat materiale_diffuso[4]= {0.8,0.0,0.0,1.0};
    GLfloat materiale_speculare[4]={0.9,0.8,0.8};
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, materiale_ambiente);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, materiale_diffuso);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materiale_speculare);
   // glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, materiale_diffuso);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50.0f);
    glEnable(GL_COLOR_MATERIAL);
    
    
    
    //luce 0 luce ambientale
    GLfloat luce_ambiente[4]={0.8,0.5,0.5,1};
    GLfloat luce_diffusa[4]= {1.0,1.0,1.0,1};
    GLfloat luce_speculare[4] = {1,1,1,1};
    GLfloat posizione_luce[4]= {0,0,0,0};
     
    glLightfv(GL_LIGHT0, GL_AMBIENT, luce_ambiente);     // Setta la luce Ambientale
    glLightfv(GL_LIGHT0, GL_DIFFUSE, luce_diffusa);     // Setta la luce Diffusa 
    glLightfv(GL_LIGHT0, GL_SPECULAR,luce_speculare);    // Posiziona la luce
    glLightfv(GL_LIGHT0, GL_POSITION,posizione_luce);    // Posiziona la luce
    
    
    
    
    ///LUCE 1 sole  del tramonto
    GLfloat lightAmbient[] = { 0.9f, 0.6f, 0.6f, 1.0f };
    GLfloat lightDiffuse[] = { 0.7f, 0.2f, 0.0f, 1.0f };
    GLfloat lightSpecular[] = { 0.1f, 0.0f, 0.0f, 1.0f };
    GLfloat lightPosition[] = { 0,0,0,0 };
    glLightfv(GL_LIGHT1, GL_AMBIENT, lightAmbient);     // Setta la luce Ambientale
    glLightfv(GL_LIGHT1, GL_DIFFUSE, lightDiffuse);     // Setta la luce Diffusa 
    glLightfv(GL_LIGHT1, GL_SPECULAR, lightSpecular); 
    glLightfv(GL_LIGHT1, GL_POSITION,lightPosition);  

    
    //abilito le luci e i materiali
    glEnable(GL_LIGHTING);      
    glEnable(GL_LIGHT1);    
    glEnable(GL_LIGHT0);
    
   // glLightModelf(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR);
        state->luce = 1;
}

void LightHandler::Move()
{
    float lightPosition[3];
    lightPosition[0] = state->cam_posX;
    lightPosition[1] = state->cam_posY+FLY_HEIGHT;
    lightPosition[2] = state->cam_posZ-20;
    
    glLightfv(GL_LIGHT1, GL_POSITION, lightPosition); 
    
}


